<?php
require_once('mysql_table.php');

class proveedor extends mysql_table{

    function __construct(){
        parent::__construct();
        $this->TableName = "PROVEEDORES";
        $this->IDField = "ID";        
        
        $this->fields['ID']  = "";
        $this->fields['NOMBRE']  = "";
        $this->fields['APELLIDO']  = "";
        $this->fields['DIRECCION']  = "";
        $this->fields['TELEFONO']  = "";
        $this->fields['FAX']  = "";
        $this->fields['MAIL']  = "";
        $this->fields['COMENTARIOS']  = "";
        $this->fields['DIA_ENTREGA']  = "";
        $this->fields['ID_FORMAS_PAGO']  = "";
        $this->fields['ID_CALIFICACION']  = "";
        $this->fields['ID_STATUS']  = "";
        
    }

    
    /**
     *@return todos los proveedores activos
     *@example para listarlos
     **/
    function buscar(){
        
        $query = "SELECT PROVEEDORES.*, STATUS.DESCRIPCION AS STATUS, CALIFICACIONES.DESCRIPCION AS CALIFICACION 
        FROM  PROVEEDORES, STATUS, CALIFICACIONES 
        WHERE ID_STATUS = 1 
        AND PROVEEDORES.ID_STATUS = STATUS.ID 
        AND PROVEEDORES.ID_CALIFICACION = CALIFICACIONES.ID";
        $salida = $this->tovector_assoc_query($query);
        //print($query);
        return $salida;
            
    }
    
    function buscar_articulo($id_articulo){
        
        $query = "SELECT PROVEEDORES.*
        FROM  PROVEEDORES, ARTICULOS 
        WHERE PROVEEDORES.ID_STATUS = 1 
        AND ARTICULOS.ID_STATUS = 1 
        AND ARTICULOS.ID = ".$id_articulo."  
        AND PROVEEDORES.ID = ARTICULOS.ID_PROVEEDOR";
        
        $salida = $this->tovector_assoc_query($query);
        //print($query);
        return $salida;
            
    }
    
    function unique($Column,$Value){
        $query = "SELECT * FROM " . $this->TableName ." WHERE ".$Column."=" . $Value." AND ID_STATUS=1";
        $result = $this->runquery($query);
        //print_r($query);
        if ($this->SQLObject->num_rows($result) == 0) {
            return false;
        } else {
            $this->getdata($result);
            return true;
        }
    }
    
}
?>
